<?php

require_once ('LikeMVC/Controller/Abstract.php');

class LikeMVC_Controller_Task extends LikeMVC_Controller_Abstract {
	
	protected $_classMethods;
	
	public function dispatch($task) {
		$this->preDispatch ();
		
		if (null === $this->_classMethods) {
			$this->_classMethods = get_class_methods ( $this );
		}
		
		if (in_array ( $task, $this->_classMethods )) {
			$this->$task ();
		} else {
			$this->__call ( $task, array () );
		}
		$this->postDispatch ();
	}
	
	public function __call($methodName, $params) {
		if ('Task' == substr ( $methodName, - 4 )) {
			$task = substr($methodName, 0, strlen($methodName) - 4);
			require_once 'LikeMVC/Exceptions/NotFound.php';
			throw new LikeMVC_Exceptions_NotFound (sprintf('Task "%s" does not exist', $task));
		} else {
			throw new Exception(sprintf('Method "%s" does not exist', $task), 500);
		}
	}
}

?>